export const useVerifiedImage = (imageUrl: MaybeRef<string>, defaultImage: MaybeRef<string> = '/default-image.jpg') => {
    const displayImage = ref(unref(defaultImage))
    
    const verifyImage = async (url: string) => {
      displayImage.value = unref(defaultImage) // 先重置为默认图片
      
      if (!url) return
      
      try {
        // 使用 fetch 检查图片是否存在
        const response = await fetch(url, { method: 'HEAD' })
        if (response.ok) {
          displayImage.value = url // 只有成功时才更新
        }
      } catch (error) {
        console.error('Image verification failed:', error)
      }
    }
  
    // 监听 URL 变化
    watchEffect(() => {
      verifyImage(unref(imageUrl))
    })
  
    return { displayImage }
  }